Skip to content

feat(java): parse quoted JSON scalar values - #3967

Merged
chaokunyang merged 2 commits into
apache:mainfrom
chaokunyang:fix_decimal_string_quoted_parse
Aug 23, 2026
Merged

feat(java): parse quoted JSON scalar values#3967
chaokunyang merged 2 commits into
apache:mainfrom
chaokunyang:fix_decimal_string_quoted_parse

Conversation

@chaokunyang

@chaokunyang chaokunyang commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Why?

Financial and other APIs commonly encode boolean and numeric values as JSON strings. Fory JSON
previously rejected those values for declared scalar targets, so users had to register custom
codecs even for standard types such as BigDecimal.

What does this PR do?

  • Accept quoted ordinary token text for declared boolean, byte, short, int, long, float, double,
    BigInteger, and BigDecimal targets without a configuration switch.
  • Parse quoted values through the same representation-specific token parsers as native JSON
    tokens, without allocating an intermediate String or another per-value carrier.
  • Keep natural dynamic JSON typing: a quoted value read as Object remains a String; a quoted
    numeric value read as Number is a Double.
  • Cover roots, generated and interpreted object codecs, arrays, collections, maps, Latin1, UTF-8,
    UTF-16, arbitrary-precision limits, and malformed quoted input.
  • Document the user-visible coercion behavior.

Related issues

N/A.

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

Yes. Declared boolean and numeric JSON targets now accept their ordinary token text inside a JSON
string. Serialization output remains unchanged.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

Environment: macOS arm64, OpenJDK 25.0.3, JMH 1.37, one fork/thread, -Xms2g -Xmx2g, one-second
iterations, and -prof gc.

Unquoted generated primitive POJO parsing against the exact merge-base artifact:

Input Baseline Current Change Allocation
Latin1 60.159 ns/op 58.797 ns/op -2.263% 40.000 / 40.000 B/op
UTF-8 56.840 ns/op 55.550 ns/op -2.270% 40.000 / 40.000 B/op
UTF-16 131.191 ns/op 133.706 ns/op +1.917% 40.001 / 40.001 B/op

Quoted and unquoted normalized allocations are equal to JMH counter precision:

Case Unquoted Quoted
BigDecimal 184.001 B/op 184.001 B/op
BigInteger 264.001 B/op 264.002 B/op
Combined scalar POJO 592.003 B/op 592.003 B/op

Final-head targeted validation:

ENABLE_FORY_DEBUG_OUTPUT=1 mvn -q -pl fory-json -Dtest=JsonScalarTest \
  spotless:check checkstyle:check test

139 tests passed with no failures, errors, or skips.

@chaokunyang
chaokunyang merged commit 0ee14a4 into apache:main Aug 23, 2026
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants